app.controller('RtTaskResListCtrl', function ($scope, ajax, $modal, toaster) {

	var updater = new Req.PUT({ resource: $scope.resource });

	$scope.reload = $scope.page.loader('task/rt/resource/{pageIndex}/{pageSize}/page');
	$scope.$on('pageIndex', function (event, p) { $scope.reload(p, $scope.queryMap); });
	$scope.reload(1);

	//模糊查询
	$scope.timeRange = {};
	$scope.queryMap = {};
	$scope.query = function () {
		if ($scope.timeRange.startTime && $scope.timeRange.endTime) {
			var starTime = $scope.timeRange.startTime.pattern("yyyy-MM-dd");
			var endTime = $scope.timeRange.endTime.pattern("yyyy-MM-dd");
			$scope.queryMap.createTime = starTime + "#@" + endTime;
		} else if ($scope.timeRange.startTime == null || $scope.timeRange.endTime == null) {
			delete $scope.queryMap.createTime;
		}
		$scope.reload(1, $scope.queryMap);
	};

	// 新增、更新
	$scope.write = function (size, current_data, submit_type) {
		$scope.current_data = angular.copy(current_data);
		var modalInstance = $modal.open({
			templateUrl: 'template/rent/resource/writeModal.html?v=be008be514',
			controller: 'RtTaskResModalCtrl',
			size: size,
			resolve: {
				param: function () {
					return {
						"data": $scope.current_data,
						"type": submit_type
					};
				}
			}
		});

		modalInstance.result.then(function (param) {
			if (param.type == 'update') {
				updater.fields = param.data;
				updater.id = param.data.id;
				updater.resource = 'task/rt/update';
				$scope.page.mod(updater, $scope.reload);
			}
		});
	};
});

app.filter('statusFilter', function () {
	return function (status) {
		switch (status) {
			case 1: return '已创建';
			case 2: return '已分配';
			case 3: return '进行中';
			case 4: return '已完成';
			case 5: return '已取消';
			case 6: return '已失败';
			case 7: return '已中止';
			case 8: return '未执行';
			default: return '';
		}
	};
});
